package com.bocai.controller;

import com.bocai.service.UploadFileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Api(value = "商户上传文件相关接口")
@Controller
@RequestMapping("imgUploadCtl")
public class ImgUploadController {

	/** 依赖注入上传文件Service */
	@Autowired
	private UploadFileService uploadFileService;
	
	
	/**
	* @Title: imgUpload 
	* @Description: B端，上传图片
	* @param @param imageFile
	* @param @param request
	* @param @return    
	* @return Map<String,Object>     
	* @throws
	 */
	@ApiOperation(value = "C端|用户上传图片",notes = "ajax上传图片")
	@ResponseBody
	@RequestMapping(value = "imgUpload" , method = RequestMethod.POST)
	public Map<String, Object> imgUpload(@RequestParam(value = "img") MultipartFile imageFile, HttpServletRequest request){
		
		//调用Service
		return uploadFileService.uploadImageToServer(imageFile, request);
	}
	
	
	/**
	* @Title: webImgCrop 
	* @Description: B端，用户上传文件
	* @param @param imgUrl
	* @param @param imgW
	* @param @param imgH
	* @param @param imgX1
	* @param @param imgY1
	* @param @param cropW
	* @param @param cropH
	* @param @param request
	* @param @return    
	* @return Map<String,Object>     
	* @throws
	 */
	@ApiOperation(value = "C端|用户上传文件",notes = "用户上传文件")
	@ResponseBody
	@RequestMapping(params="webImgCrop", method= RequestMethod.POST)
	public Map<String, Object> webImgCrop(@RequestParam(value="imgUrl",required=false) String imgUrl,
			@RequestParam(value = "imgW",required=false) double imgW,
			@RequestParam(value = "imgH",required=false) double imgH,
			@RequestParam(value = "imgX1",required=false) Integer imgX1,
			@RequestParam(value = "imgY1",required=false) Integer imgY1,
			@RequestParam(value = "cropW",required=false) Integer cropW,
			@RequestParam(value = "cropH",required=false) Integer cropH,
			HttpServletRequest request) {
		//调用Service
		return uploadFileService.webImgCrop(imgUrl, imgW, imgH, imgX1, imgY1, cropW, cropH, request);
	}
	
}
